home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / PickOne / sources / PickOne_utility.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  3.4 KB  |  142 lines  |  [TEXT/CWIE]

  1. /*  utility.c                                                                            
  2.  
  3.     Nick Thompson
  4.     Michael Bishop - August 21 1996                                                    
  5.     (c)1994-96 Apple computer Inc., All Rights Reserved                                
  6.  
  7. */
  8.  
  9. /* --------------------------------------------------------------------
  10. ** INCLUDES
  11. */
  12. #include    <QuickDraw.h>
  13. #include    <Events.h>
  14.  
  15. #include    <math.h>
  16.  
  17. #include    "PickOne_utility.h"
  18.  
  19. #include    "QD3D.h"
  20. #include    "QD3DMath.h"
  21. #include    "QD3DGroup.h"
  22.  
  23.  
  24. /* --------------------------------------------------------------------
  25. ** GLOBAL VARIABLES
  26. */
  27.  
  28.  
  29. /* --------------------------------------------------------------------
  30. ** LOCAL FUNCTION DEFINITIONS
  31. */
  32.  
  33.  
  34. /*    --------------------------------------------------------------------
  35. **    Utility_HiWrd
  36. **    DESCRIPTION
  37. */
  38. short Utility_HiWrd(long aLong)
  39. {
  40.     return    (((aLong) >> 16) & 0xFFFF) ;
  41. }
  42.  
  43. /*    --------------------------------------------------------------------
  44. **    Utility_LoWrd
  45. **    DESCRIPTION
  46. */
  47. short Utility_LoWrd(long aLong)
  48. {
  49.     return    ((aLong) & 0xFFFF) ;
  50.  
  51. }
  52.  
  53. /*    --------------------------------------------------------------------
  54. **    Utility_DebugString
  55. **    Abstract GetMouse Function for Porting
  56. */
  57. void Utility_DebugString(char    *theMessage)
  58. {
  59.     DebugStr((const unsigned char *)theMessage);
  60. }
  61.  
  62.  
  63. /*    --------------------------------------------------------------------
  64. **    Utility_MyGetMouse
  65. **    Abstract GetMouse Function for Porting
  66. */
  67. void Utility_MyGetMouse(TQ3Point2D *thePoint)
  68. {
  69.     Point macPoint;
  70.     
  71.     GetMouse(&macPoint);
  72.     
  73. /*    GlobalToLocal(&macPoint);
  74. */    
  75.     thePoint->x = (float)(macPoint.h);
  76.     thePoint->y = (float)(macPoint.v);
  77. }
  78.  
  79. /*    --------------------------------------------------------------------
  80. **    Utility_MyStillDown
  81. **    Abstract StillDown Function for Porting
  82. */
  83. int    Utility_MyStillDown(void)
  84. {
  85.     return StillDown();
  86. }
  87.  
  88. /*    --------------------------------------------------------------------
  89. **    Utility_GetUpVector
  90. **    Returns a default vector that points as much toward the y axis as it can.
  91. **    Expects the vectors to be normalized.
  92. **    At this point, what to do if the forward vector lies on the y axis is a
  93. **    point of thought. Currently, it returns vector pointing down the -Z axis.
  94. */
  95. void    Utility_GetUpVector(const TQ3Vector3D *theForwardVector, TQ3Vector3D *theUpVector)
  96. {
  97.     TQ3Vector3D    theOrthogonalVector,  tempVector, theForwardVectorCopy = *theForwardVector;
  98.     
  99.     if ( (theForwardVectorCopy.x == 0.0) && (theForwardVectorCopy.z == 0.0) ) {
  100.         theUpVector->x = 0.0; theUpVector->y = 0.0; theUpVector->z = -1.0; 
  101.     } else {
  102.  
  103.         Q3Vector3D_Set ( &tempVector, 0.0, 1.0, 0.0 ) ;
  104.         Q3Vector3D_Cross(&tempVector, (const TQ3Vector3D *)&theForwardVectorCopy, &theOrthogonalVector);
  105.         Q3Vector3D_Cross(&theForwardVectorCopy, (const TQ3Vector3D *)&theOrthogonalVector, &tempVector);
  106.         
  107.         Q3Vector3D_Normalize(&tempVector, theUpVector);    
  108.     }
  109. }
  110.  
  111. /*    --------------------------------------------------------------------
  112. **    Utility_GetEnclosingGroup
  113. **    Takes a hit path and returns the group enclosing the leaf of the path
  114. */
  115. TQ3Object    Utility_GetEnclosingGroup(const TQ3HitPath *theHitPath)
  116. {
  117.     long            subGroupDepth;
  118.     TQ3GroupObject    group, subGroup;
  119.     long            i;
  120.  
  121.     if ( theHitPath->depth < 1 ) {
  122.         return NULL;
  123.     }
  124.     
  125.     if ( theHitPath->depth == 1 ) {
  126.         return theHitPath->rootGroup;
  127.     }
  128.     
  129.     subGroupDepth = theHitPath->depth - 1;
  130.     group = theHitPath->rootGroup;
  131.     
  132.     for (i = 0; i < subGroupDepth; i++) {
  133.         if (Q3Group_GetPositionObject(theHitPath->rootGroup, theHitPath->positions[i], &subGroup) == kQ3Success)
  134.         {
  135.             if ( group != theHitPath->rootGroup) {
  136.                 Q3Object_Dispose(group);
  137.             }
  138.             group = subGroup;
  139.         }
  140.     }
  141.     return group;    
  142. }